package ils.web.action;

import com.opensymphony.xwork2.Preparable;
import ils.domain.issue.model.Reserve;
import ils.util.SpringUtil;
import ils.web.model.ReservationDetails;
import ils.services.IssueService;

import java.util.List;
import java.util.Map;

import ils.web.util.WebUtil;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class ReservationsAction extends ActionSupport implements SessionAware, Preparable
{
    private Map<String, Object> session;
    private IssueService issueService;
    private List<ReservationDetails> reservationDetailsList;
    private int firstResult;
    public String execute() throws Exception
    {
        List<Reserve> reserves = issueService.getReservations(firstResult);
        reservationDetailsList = WebUtil.convertToReservationDetails(reserves);
        firstResult += 10;
        return SUCCESS;
    }
    @Override
    public void setSession(Map<String, Object> arg0)
    {
        this.session = arg0;
    }
    public void setIssueService(IssueService issueService)
    {
        this.issueService = issueService;
    }
    public List<ReservationDetails> getReservationDetailsList()
    {
        return reservationDetailsList;
    }
    public void setReservationDetailsList(List<ReservationDetails> reservationDetailsList)
    {
        this.reservationDetailsList = reservationDetailsList;
    }
    public int getFirstResult()
    {
        return firstResult;
    }

    public void setFirstResult(int firstResult)
    {
        this.firstResult = firstResult;
    }

    @Override
    public void prepare() throws Exception {
        issueService = (IssueService) SpringUtil.getApplicationContext().getBean("issueService");
    }
}
